Fix GDB write. Failure was caused by change from CVS to SVN which changed $Date...
authorrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 14 Jan 2012 21:31:37 +0000 (21:31 +0000)
committerrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 14 Jan 2012 21:31:37 +0000 (21:31 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4140 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/gdb.c

index 86100201a48262524ab793ba06476716bf914ee3..08167991ef022dec4b765f08686921b7cf7f2c3e 100644 (file)
@@ -1175,7 +1175,7 @@ write_header(void)
 {
   char buff[128], tbuff[32];
   char* c;
-  int len;
+  int len, n = 0;
   struct tm tm;
 
   FWRITE_CSTR("MsRcf");
@@ -1211,10 +1211,22 @@ write_header(void)
   */
 
   memset(&tm, 0, sizeof(tm));
-  sscanf(gdb_release_date+7, "%d/%d/%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
+
+  n = sscanf(gdb_release_date+7, "%d/%d/%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
+  if (n != 6) { 
+    // The $Date string in gdb_release_date[] above is bad.
+    fatal(MYNAME ": internal date format error on %s\n", gdb_release_date + 7);
+  }
+
   tm.tm_year -= 1900;
   tm.tm_mon -= 1;
-  strftime(tbuff, sizeof(tbuff), "%b %d %Y*%H:%M:%S", &tm);
+
+  n = strftime(tbuff, sizeof(tbuff), "%b %d %Y*%H:%M:%S", &tm);
+  if (n == 0) {
+    // The build of the struct tm was bad.
+    fatal(MYNAME ": internal date generation error for %s\n", gdb_release_date + 7);
+  }
+
   snprintf(buff, sizeof(buff), "A].GPSBabel-%s*%s", gpsbabel_version, tbuff);
 #endif
   len = strlen(buff);